home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / lh113src.zip / UTIL.C < prev   
Text File  |  1989-05-04  |  3KB  |  147 lines

  1. /*************************************************
  2.         LHarc version 1.13 (c)Yoshi, 1988-89.
  3.         utility module : 1989/ 5/ 4
  4.  
  5. HTAB = 4
  6. *************************************************/
  7.  
  8. #include <stddef.h>
  9. #include <dos.h>
  10. #include <ctype.h>
  11.  
  12. #define iskanji(c) ((uchar)(c) >= 0x80 && (uchar)(c) <= 0x9f || \
  13.                     (uchar)(c) >= 0xe0 && (uchar)(c) <= 0xfd)
  14. typedef unsigned char uchar;
  15. typedef unsigned int  uint;
  16. typedef unsigned long ulong;
  17.  
  18. /*******************************
  19.     strupr for Japanese strings
  20. *******************************/
  21. uchar *j_strupr(uchar *p)
  22. {
  23.     uchar *q;
  24.  
  25.     for (q = p; *q; q++) {
  26.         if (iskanji(*q)) {
  27.             q++;
  28.             if (*q == 0)
  29.                 break;
  30.         } else {
  31.             *q = toupper(*q);
  32.         }
  33.     }
  34.     return p;
  35. }
  36.  
  37. /*******************************
  38.     strcmp for Japanese strings
  39. *******************************/
  40. int j_strcmp(char *p, char *q)
  41. {
  42.     int c, md0, md1;
  43.  
  44.     for (md0 = 0;
  45.          ((c = (uchar)*p - (uchar)*q) == 0) && (*p != 0); p++, q++) {
  46.         if (md0) {
  47.             md0 = 0;
  48.         } else {
  49.             md0 = iskanji((uchar)*p);
  50.         }
  51.     }
  52.     if (md0 == 0) {
  53.         md0  = iskanji((uchar)*p);
  54.         md1 = iskanji((uchar)*q);
  55.         if (md0) {
  56.             if (md1 == 0) return 1;
  57.         } else {
  58.             if (md1) return -1;
  59.         }
  60.     }
  61.     return c;
  62. }
  63.  
  64. /*******************************
  65.   strchr for Japanese strings
  66.     (subset of jstrchr)
  67.   can't search Kanji character
  68. *******************************/
  69. uchar *j_strchr(char *p, uint c)
  70. {
  71.     uchar *q, a;
  72.  
  73.     q = (uchar *)p;
  74.     while ((a = *q) != c) {
  75.         if (a == 0) return NULL;
  76.         if (iskanji(a)) {
  77.             if (*++q == 0) return NULL;
  78.         }
  79.         q++;
  80.     }
  81.     return q;
  82. }
  83.  
  84. /*******************************
  85.   strrchr for Japanese strings
  86.     (subset of jstrrchr)
  87.   can't search Kanji character
  88. *******************************/
  89. uchar *j_strrchr(char *p, uint c)
  90. {
  91.     uchar *q, *r;
  92.  
  93.     q = p - 1;
  94.     while ((r = j_strchr(q + 1, c)) != NULL) {
  95.         q = r;
  96.     }
  97.     if (q < p) return NULL;
  98.     return q;
  99. }
  100.  
  101. /*******************************
  102.     get file attributes
  103. *******************************/
  104. int getfattr(uchar *fn)
  105. {
  106.     _DX = (uint)fn;
  107.     _CX = 0x8000;
  108.     _AX = 0x4300;
  109.     __int__(0x21);
  110.     return _CX;
  111. }
  112.  
  113. /*******************************
  114.     set file attributes
  115. *******************************/
  116. void setfattr(uchar *fn, int attr)
  117. {
  118.     _DX = (uint)fn;
  119.     _CX = attr;
  120.     _AX = 0x4301;
  121.     __int__(0x21);
  122. }
  123.  
  124. /*******************************
  125.     get the setting of
  126.     switch character
  127. *******************************/
  128. uchar getswchar(void)
  129. {
  130.     _AX = 0x3700;
  131.     __int__(0x21);
  132.     return _DL;
  133. }
  134.  
  135. /*******************************
  136.     convert    '/' to '\'
  137.     ('\' code is assigned to
  138.     the Yen-mark in Japan.)
  139. *******************************/
  140. void slash2yen(uchar *p)
  141. {
  142.     for (; *p != '\0'; p++) {
  143.         if (*p == '/')
  144.             *p = '\\';
  145.     }
  146. }
  147.